package cn.com.jonpad.demo06_simple_project.component;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆拦截
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
	/**
	 * 目标方法执行前
	 * @param request
	 * @param response
	 * @param handler
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		Object info = request.getSession().getAttribute("account");
		if(info == null){
			request.getRequestDispatcher("/noLogin").forward(request,response);
			return false;
		}else{
			return true;
		}
	}
}
